package com.zhu.day.util;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import java.time.LocalDateTime;
import java.util.concurrent.*;

public class ThreadExecuter {
    public static final ExecutorService executor;
    public static final ExecutorService bizExecutor;
    public static final ScheduledExecutorService scheduledExecutor;

    public ThreadExecuter() {
    }

    public static void initLoadSelf() {
    }

    public static void main(String[] args) {
        scheduledExecutor.scheduleAtFixedRate(() -> {
            System.out.println("run {{" + Thread.currentThread().getName() + "}}> "
                    + LocalDateTime.now());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, 0, 3, TimeUnit.SECONDS);


    }

    static {
        executor = new ThreadPoolExecutor(16, 16,
                0L, TimeUnit.MILLISECONDS,
                new SynchronousQueue<>(),
                new ThreadPoolExecutor.CallerRunsPolicy());

        bizExecutor = new ThreadPoolExecutor(50, 50,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(20000),
                new ThreadPoolExecutor.CallerRunsPolicy());

        scheduledExecutor = Executors.newScheduledThreadPool(5);


        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            executor.shutdown();
            bizExecutor.shutdown();
            scheduledExecutor.shutdown();
            System.out.println("add shutdown!");
        }));
    }
}
